# -*- coding: utf-8 -*- 
import wx
from settings import magnifier_factor as mfactor

class MagWin(wx.Window):

        def __init__(self, parent):
            wx.Window.__init__(self, parent, -1)
            self.image = None
            self.x = 0 ;self.y = 0
            self.Bind(wx.EVT_PAINT, self.OnPaint)

        def refresh(self, img,x,y):
            self.image = img
            self.x = x ;self.y = y
            self.draw()
            self.GetParent().SetClientSize((self.image.GetWidth() * mfactor, self.image.GetHeight()*mfactor))
            self.Refresh()
            #print x,y
            
        def draw(self):    
            w,h = self.image.GetWidth(),self.image.GetHeight()
            
            self.buffer = wx.EmptyBitmap(mfactor*w,mfactor*h)
            dc = wx.BufferedDC(wx.ClientDC(self), self.buffer)
            dc.Clear()
            dc.SetUserScale(mfactor, mfactor)
            dc.DrawBitmap(wx.BitmapFromImage(self.image),0 ,0)
            dc.CrossHair(self.x , self.y )
            
        def OnPaint(self, event):
            dc = wx.BufferedPaintDC(self, self.buffer)

class MagFrame(wx.Frame):
        def __init__(self, parent):
            x,y = parent.mf_position
            x  = x - 200
            y = y - 80
            wx.Frame.__init__(self, parent , title="放大镜",size=(450,400), 
                                style = wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX|wx.STAY_ON_TOP,
                            pos = (x,y))
            self.win = MagWin(self)
            self.Bind(wx.EVT_CLOSE, self.OnClose)
            
        def OnClose(self, event):
            self.close()
            
        def close(self):
            self.GetParent().magnifier=None
            self.Destroy()
            